package cn.ytr.crm.web.controller;

import cn.ytr.crm.domain.CustomerTraceHistory;
import cn.ytr.crm.query.CustomerTraceHistoryQueryObject;
import cn.ytr.crm.service.ICustomerTraceHistoryService;
import cn.ytr.crm.service.IEmployeeService;
import cn.ytr.crm.service.ISystemDictionaryItemService;
import cn.ytr.crm.util.JsonResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/customerTraceHistory")
@Controller
public class CustomerTraceHistoryController {

    @Autowired
    private ICustomerTraceHistoryService customerTraceHistoryService;
    @Autowired
    private IEmployeeService employeeService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;

    /**
     * 显示 客户跟踪记录列表页
     */
    @RequiresPermissions(value = {"访问:客户跟踪记录列表页面", "customerTraceHistory:list"}, logical = Logical.OR)
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") CustomerTraceHistoryQueryObject qo, Model model) {
        //用分页插件
        model.addAttribute("pageInfo", customerTraceHistoryService.query(qo));

        //跟进方式下拉框数据共享
        model.addAttribute("traceTypes", systemDictionaryItemService.selectByDicSn("communicationMethod"));

        return "CustomerTraceHistory/list";
    }


    /**
     * 处理 去增加或编辑客户跟踪记录页提交的
     */
    @RequiresPermissions(value = {"操作:新增或修改客户跟踪记录", "customerTraceHistory:saveOrUpdate"}, logical = Logical.OR)
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(CustomerTraceHistory entity) {
        JsonResult jsonResult = new JsonResult();
        try {
            customerTraceHistoryService.saveOrUpate(entity);
            return jsonResult;
        } catch (Exception e) {
            jsonResult.mark("服务器提示：操作客户跟踪记录出错");
            e.printStackTrace();
            return jsonResult;
        }

    }


    /**
     * 处理 删除客户跟踪记录
     */
    @ResponseBody
    @RequiresPermissions(value = {"操作:删除客户跟踪记录", "customerTraceHistory:delete"}, logical = Logical.OR)
    @RequestMapping("/delete")
    public JsonResult delete(Long id) {
        JsonResult jsonResult = new JsonResult();
        try {
            customerTraceHistoryService.delete(id);
            return jsonResult;
        } catch (Exception e) {
            jsonResult.mark("服务器提示：删除客户跟踪记录操作出错");
            e.printStackTrace();
            return jsonResult;
        }

    }

}









































